<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
    <script>
        function copy(obj) {
            let res=obj instanceof Array? []:{}
            for (const [key,v] of Object.entries(obj)) {
                res[key]=typeof v=='object' ?copy(v):v
            }
            return res
        }
        let hd = [1,2,3,{name:'yahoo'}]
        c=copy(hd)
        c[3].name='sfd'
        console.log(c)
        console.log(hd)

        let test = {name:{url:'yahoo.com'}}
        c1=copy(test)
        c1.name.url='baidu.com'
        console.log(test)
        console.log(c1)
    </script>
</body>
</html>